#include "Newton.h"
#define PI acos(-1)
using namespace std;

double fun(double x){
    double f;
    f=1/(1+25*pow(x,2));
    return f;
}
int main(){
    float n=20;
    vector<double> x(n);
    for (int i=0; i<n ;i ++){
        x[i]=cos(PI*(2*i+1)/(2*n));
    }

    vector<double> y(n);
    for (int i=0;i<n;i++){
        y[i]=fun(x[i]);
    }


    Polynomial f(n-1);
    vector<double> a_0(n);
    a_0=f.makepoly(x,y);
    cout <<"Pn(x)=";
    for (int i=0;i<n;i++){
        cout << a_0[i];
        if (i>=1){
        cout <<"*(x-("<< x[0] <<"))";
        }
        for(int j=1;j<i;j++){
            cout << ".*(x-("<< x[j]<<"))";
        }
        if(a_0[i+1]<0){
        }
        else{
        cout <<"+";
        }
    }
    cout << a_0[n];
    for (int j=0;j<n;j++){
        cout << ".*(x-("<< x[j]<<"))";
    }
    cout <<endl;
    return 0;
}
